]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: improve bad-markup handling
authorDan Winship <danw@gnome.org>
Wed, 4 May 2011 15:15:45 +0000 (11:15 -0400)
committerDan Winship <danw@gnome.org>
Wed, 27 Jul 2011 13:29:03 +0000 (09:29 -0400)
_fixMarkup() was supposed to be ensuring that the markup we passed to
clutter was correct, but it was validating the syntax incorrectly, and
wasn't checking that the markup was valid (or even well-formed). This
is bad because if you pass bad pango markup to
clutter_text_set_markup(), it will g_warn and drop the string on the
floor.

Fix by fixing up the regexps, and then calling Pango.parse_markup() on
the result, and just xml-escaping everything if parse_markup() fails.

https://bugzilla.gnome.org/show_bug.cgi?id=650298

js/ui/messageTray.js

index 41475c1061a34817bf294ef4a8fb9a017044f2d1..4dc949e32f9a539dea190b28a53e457ea9fd29d8 100644 (file)
@@ -68,14 +68,19 @@ function _fixMarkup(text, allowMarkup) {
         // Support &amp;, &quot;, &apos;, &lt; and &gt;, escape all other
         // occurrences of '&'.
         let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&amp;');
+
         // Support <b>, <i>, and <u>, escape anything else
         // so it displays as raw markup.
-        return _text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, '&lt;$1');
-    } else {
-        // Escape everything
-        let _text = text.replace(/&/g, '&amp;');
-        return _text.replace(/</g, '&lt;');
+        _text = _text.replace(/<(?!\/?[biu]>)/g, '&lt;');
+
+        try {
+            Pango.parse_markup(_text, -1, '');
+            return _text;
+        } catch (e) {}
     }
+
+    // !allowMarkup, or invalid markup
+    return GLib.markup_escape_text(text, -1);
 }
 
 function URLHighlighter(text, lineWrap, allowMarkup) {